package com.dingqb.ktdemo.oop.objectexpression

// 对象表达式
class Expression {

}

class C {
	// 私有函数，所以其返回类型是匿名对象类型
	private fun foo() = object {
		val x: String = "x"
	}

	// 公有函数，所以其返回类型是 Any
	fun publicFoo() = object {
		val x: String = "x"
	}

	fun bar() {
		val x1 = foo().x        // 没问题
		//val x2 = publicFoo().x  // 错误：未能解析的引用“x”
	}
}

open class A(x: Int) {
	public open val y: Int = x
	public open fun Ibb(): Int = 0
}

interface B {
	public open val bb: Int
}

val ab: A = object : A(1), B {
	override val y = 15
	override val bb = 10;
	override fun Ibb(): Int = bb;
}


object AA {
	public open var aa: String = "this is a str";
}

class AAB {
	var aag: String = "this is a class aag";

	object AABObj {
		var aabobj: String = "this is a class -> object field";
	}
}

object AAChild : Any() {
	override fun toString(): String {
		return this.toString();
	}
}




class Site {
	var name = "菜鸟教程"

	object DeskTop {
		var url = "www.runoob.com"
		fun showName() {
			//print { "desk legs $name" } // 错误，不能访问到外部类的方法和变量
			println("desk legs --");
		}

		fun showName1() = "123"
	}
}


fun main(args: Array<String>) {
	println(ab.y)
	println(ab.Ibb())
	var aa = AA
	println(aa.aa);
	var aab = AAB();
	println(aab.aag)
	println(AAB.AABObj.aabobj)
	Site.DeskTop.showName();
	println(Site.DeskTop.url)
	println(Site.DeskTop.showName1())
}


